ACTION=function(){} //Khai bao class

/**********Insert**************/
ACTION.prototype.insert=function(uid,fullname){
	var fncSuc = XHR.Delegate(this,this.insertSuc);
	var param = {act:"insert",uid:uid,fullname:fullname};
	new XHR("post",fncSuc).send($PN+"/Servlet",param);
}

ACTION.prototype.insertSuc=function(r){
	var xml = new XML(r);
	if(xml.value){
		alert("Success");
	}else{
		alert(xml.msg);
	}
}

/*********List***********/
ACTION.prototype.list=function(){
	var fncSuc = XHR.Delegate(this,this.listSuc);
	
	var param = {act:"list"};
	new XHR("post",fncSuc).send($PN+"/Servlet",param);
}

ACTION.prototype.listSuc=function(r){
	var xml = new XML(r);
	if(xml.value){
		var l = xml.get("user");//getElementsByTagName
		var html = "",uid="";
		for(var i=0; i < l.length; i++){
			uid = l[i].getAttribute("uid");
			html += "<div style=\"padding:3px\"><span style=\"cursor:pointer\" onClick=\"remove('"+uid+"')\">[Remove]</span>" +
					"["+uid+"] "+l[i].getAttribute("fullname")+"</div>";
		}
		$("result").innerHTML = html;
	}else{
		alert(xml.msg);
	}
}

/*********Remove***********/
ACTION.prototype.remove=function(uid){
	var fncSuc = XHR.Delegate(this,this.removeSuc);
	var param = {act:"delete",uid:uid};
	new XHR("post",fncSuc).send($PN+"/Servlet",param);
}


ACTION.prototype.removeSuc=function(r){
	var xml = new XML(r);
	if(xml.value){
		this.list();
	}else{
		alert(xml.msg);
	}
}

function btnList(){
	new ACTION().list();
}
		
function btnInsert(){
	var uid = $N("userid")[0].value;//getDocumentByNam
	var fullname = $N("fullname")[0].value;
	new ACTION().insert(uid,fullname);
}

function remove(uid){
	new ACTION().remove(uid);
}